if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[USER_StaffResetPassWord]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[USER_StaffResetPassWord]
GO

/*
	Nguoi tao: Haidv
	Ngay tao: 16/08/2011
	Y Nghia: Doi mat khau nguoi su dung
*/
CREATE PROCEDURE [dbo].[USER_StaffResetPassWord]
		 @sStaffId varchar(50)			-- Id nguoi su dung
		,@sNewPassWord varchar(100)		-- Mat khau moi
		,@sOldPassWord varchar(100)		-- Mat khau moi
	WITH ENCRYPTION
	AS	
		Declare @p_old_pass  varchar(50)	
		SET NOCOUNT ON
				Set @p_old_pass = (select C_PASSWORD from T_USER_STAFF Where PK_STAFF  = @sStaffId)	
				if(@p_old_pass <> @sOldPassWord)
					Begin
						Select 'Thay đổi mật khẩu không thành công!' RET_ERROR
						return -100
					End						
					BEGIN TRANSACTION							
							Begin
								Update T_USER_STAFF 
										set  C_PASSWORD	= @sNewPassWord 				
								Where PK_STAFF   = @sStaffId
							End				
					COMMIT TRANSACTION 				
			SET NOCOUNT OFF
		Return 0
GO
/*
	Exec USER_StaffResetPassWord '01573b9f-7698-4902-b649-026edcea70c4' , '123456788899999'
	DBLink.[efy-user-hquangninh].dbo.USER_StaffResetPassWord '6A0F2F62-BC1E-4D7D-BA01-6660FC760681','d41d8cd98f00b204e9800998ecf8427e'
*/

